import Vue from 'vue'
import App from './App.vue'
import router from './router'
// import './plugins/element.js'

// 富文本编辑器组件
import VueQuillEditor from 'vue-quill-editor'

// 导入NProgress包对应的js和css
import NProgress from 'nprogress'

// 导入全局样式表
import './assets/css/global.css'
// 导入字体图标
import './assets/fonts/iconfont.css'
import axios from 'axios'
import ZkTable from 'vue-table-with-tree-grid'
// 配置根域名
axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/'

// axsios请求拦截
axios.interceptors.request.use(config => {
  // 展示进度条
  NProgress.start()
  // 为请求头添加Authorization
  config.headers.Authorization = window.sessionStorage.getItem('token')
  return config
})

// axsios响应拦截
axios.interceptors.response.use(config => {
  // 隐藏进度条
  NProgress.done()
  return config
})
Vue.prototype.$http = axios

Vue.config.productionTip = false

Vue.component('table-tree', ZkTable)

// 导入富文本编辑器
Vue.use(VueQuillEditor)

// 时间过滤器
Vue.filter('formatData', (value) => {
  const date = new Date(value * 1000)
  const y = date.getFullYear()
  const M = (date.getMonth() + 1).toString().padStart(2, 0)
  const d = (date.getDay()).toString().padStart(2, 0)
  const h = (date.getHours()).toString().padStart(2, 0)
  const m = (date.getMinutes()).toString().padStart(2, 0)
  const s = (date.getSeconds()).toString().padStart(2, 0)
  return `${y}-${M}-${d} ${h}:${m}:${s}`
})

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
